// 路由跳转
export function linkto (url) {
    uni.navigateTo({
        url
    })
}

// 路由跳转
export function backpage () {
    const pages = getCurrentPages()
    if (pages.length === 1) {
        uni.switchTab({
            url: '/pages/home/order'
        })
    } else {
        uni.navigateBack({ delta: 1 })
    }
}

/**
 * 提示
 * @param option 
 */
export function showToast(title, callback) {
    uni.showToast({
        title: title,
        duration: 1500,
        mask: true,
        icon: 'none'
    })
    if (typeof callback === 'function') {
        setTimeout(() => {
            callback()
        }, 1500)
    }
}

// 分转元
export function convertFenToYuan(fen) {
    if (!fen) {
        return 0
    }
    return bcdiv(fen, 100)
}

/**
 * 乘法精度 
 */
export function bcmul(a, b){
    var c = 0,
    d = a.toString(),
    e = b.toString();
    try {
        c += d.split(".")[1].length
    } catch(f) {}
    try {
        c += e.split(".")[1].length
    } catch(f) {}
    return Number(d.replace(".", "")) * Number(e.replace(".", "")) / Math.pow(10, c)
}

/**
 * 除法精度计算
 * @param {Object} number 数字
 */
export function bcdiv(a, b){
    var c, d, e = 0,
    f = 0;
    try {
        e = a.toString().split(".")[1].length
    } catch(g) {}
    try {
        f = b.toString().split(".")[1].length
    } catch(g) {}
    return c = Number(a.toString().replace(".", "")),d = Number(b.toString().replace(".", "")),bcmul(c / d, Math.pow(10, f - e))
}

/**
 * 减法精度 
 */
export function bcsub(a, b){
    var c, d, e;
    try {
        c = a.toString().split(".")[1].length
    } catch(f) {
        c = 0
    }
    try {
        d = b.toString().split(".")[1].length
    } catch(f) {
        d = 0
    }
    return e = Math.pow(10, Math.max(c, d)),(bcmul(a, e) - bcmul(b, e)) / e
}

/* 加法精度 */
export function bcadd(a, b){
    var c, d, e;
    try {
        c = a.toString().split(".")[1].length
    } catch(f) {
        c = 0
    }
    try {
        d = b.toString().split(".")[1].length
    } catch(f) {
        d = 0
    }
    return e = Math.pow(10, Math.max(c, d)),(bcmul(a, e) + bcmul(b, e)) / e
}
